Download the binaries by navigating to https://github.com/solana-labs/solana/releases/latest, download solana-release-x86_64-pc-windows-msvc.tar.bz2, then extract the archive using WinZip or similar. Open a Command Prompt and run:
cdsolana-release/setPATH=%cd%/bin;%PATH%
solana--version
Create a project
mkdirsolana-migration-xdc&&cdsolana-migration-xdc
Startinginit...================> Copying project files to /home/your/path/to/solana-migration-xdcInitsuccessful,sweet!Tryourscaffoldcommandstogetstarted:$trufflecreatecontractYourContractName# scaffold a contract$trufflecreatetestYourTestName# scaffold a testhttp://trufflesuite.com/docs
a constructor that initializes the int32 value to the given init_value,
a inc method to increment the state value,
a get method to know what is the state value
Note: Solang aims to be compatible with Solidity 0.7
Write the following code to incrementer.sol:
pragmasolidity ^0.7.0;contract incrementer {uint32private value;/// Constructor that initializes the `int32` value to the given `init_value`.constructor(uint32 initvalue) { value = initvalue; }/// This increments the value by `by`. functioninc(uint32 by) public { value += by; }/// Simply returns the current value of our `uint32`.functionget() publicviewreturns (uint32) {return value; }}
The Solang extension should compile the code automatically and a folder Build with 2 files: bundle.so and incrementer.abi.
Compile and migrate the smart contract from Solana to the XDC Network
If the extension doesn't work and you cannot see a build folder, try running this command:
const { Connection,LAMPORTS_PER_SOL,Keypair } =require('@solana/web3.js');const { Contract,Program } =require('@solana/solidity');const { readFileSync } =require('fs');constINCREMENTER_ABI=JSON.parse(readFileSync('./build/incrementer.abi','utf8'));constPROGRAM_SO=readFileSync('./build/bundle.so');(asyncfunction () {console.log('Connecting to your local Solana node ...');constconnection=newConnection(//'https://api.mainnet-beta.solana.com','https://api.devnet.solana.com',//'http://localhost:8899','confirmed');constpayer=Keypair.generate();console.log('Airdropping SOL to a new wallet ...');constsignature=awaitconnection.requestAirdrop(payer.publicKey,LAMPORTS_PER_SOL);awaitconnection.confirmTransaction(signature,'confirmed');constprogram=Keypair.generate();conststorage=Keypair.generate();constcontract=newContract(connection,program.publicKey,storage.publicKey,INCREMENTER_ABI, payer);awaitcontract.load(program,PROGRAM_SO);console.log('Program deployment finished, deploying the incrementer contract ...');awaitcontract.deploy('incrementer', [1], storage,1000);constres=awaitcontract.functions.inc(2);console.log('Adding number 2 to the value', res)constres2=awaitcontract.functions.get();console.log('state: '+res2.result);})();
Run this command to config the devnet url for solana: