initial version of wrc20 token
Is there a way to deploy the contract? The following code fails on estimateGas with Transaction execution error
let Web3 = require("web3")
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
let rustCode = '0x' + fs.readFileSync("./rust.wasm").toString('hex');
var interface = [
{
type: "function",
name: "balance",
inputs: [{"name": "acc", "type": "address"}],
outputs: [{"name": "returnValue", "type": "uint64"}],
constant: true
},
{
type: "function",
name: "transfer",
inputs: [{"name": "to", "type":"address"}, {"name": "amount", "type": "uint64"}],
outputs: []
}
]
async function upload() {
let accs = await web3.eth.personal.getAccounts()
web3.eth.defaultAccount = accs[0]
var TokenContract = new web3.eth.Contract(interface, { data: rustCode, from: web3.eth.defaultAccount });
var TokenDeployTransaction = TokenContract.deploy({data: rustCode});
await web3.eth.personal.unlockAccount(web3.eth.defaultAccount, "")
let gas = await TokenDeployTransaction.estimateGas() // Fails here!
let contract = await TokenDeployTransaction.send({gasLimit: gas, from: web3.eth.defaultAccount});
console.log("Address of new contract: " + contract.options.address);
}
upload()
@yglukhov Contracts are deployed using ewasm-studio (http://ewasm.ethereum.org/studio/) or the explorer's deployer (http://ewasm.ethereum.org/explorer/deploy).
You cannot deploy your wasm contract directly, it has to be wrapped into a deployer wasm module which when executed returns your contract bytecode, both ewasm-studio and the explorer's deployer wraps the contract into a deployer wasm module.
I've made a script to deploy an ewasm contract without ewasm-studio/explorer's deployer , you can find it here: https://github.com/hugo-dc/deploy-ewasm
It is using wasm-chisel (https://github.com/wasmx/wasm-chisel) to wrap the wasm contract into a deployer. You can find more information in the README.