1. Install truffle (preferably v5.3.0+, sometimes with v5.1.33, @truffle/hdwallet-provider
does not work)
2. Create a metacoin project, unbox metacoin truffle box, and install @truffle/hdwallet-provider
mkdir truffle
cd truffle
truffle unbox truffle
npm install --save-dev @truffle/hdwallet-provider
3. Create deploy script ./migrations/1_deploy_contracts.js
const helloPosiChain = artifacts.require("HelloPosiChain");
module.exports = function(deployer) {
deployer.deploy(helloPosiChain)
.then(() => helloPosiChain.deployed())
.then(_instance => console.log("HelloPosiChain deployed to:", _instance.address));
};
4. Modify truffle-config.js
to add POSI Chain networks. Make sure to add your mnemonic or private key.
const HDWalletProvider = require('@truffle/hdwallet-provider');
const mnemonic = '<ADD-YOUR-MNEMONIC-HERE>';
const privateKeyTest = '<ADD-YOUR-PRIVATE-KEY-HERE>';
module.exports = {
networks: {
posichain_mainnet: {
provider: () => {
return new HDWalletProvider({
mnemonic,
providerOrUrl: 'https://api.posichain.org/', // this is RPC for mainnet shard 0
derivationPath: `m/44'/1023'/0'/0/`
});
},
network_id: 900000, // mainnet
},
posichain_testnet: {
provider: () => {
if (!privateKeyTest.trim()) {
throw new Error(
'Please enter a private key with funds, you can use the default one'
);
}
return new HDWalletProvider({
privateKeys: [privateKeyTest],
providerOrUrl: 'https://api.s0.t.posichain.org/'// this is RPC for testnet shard 0
});
},
network_id: 910000, // testnet
},
},
};
4. Compile and deploy
truffle compile
truffle deploy --network posichain_testnet